package com.jkt.rms.dataservice.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;


import com.jkt.rms.business.AppRole;
import com.jkt.rms.business.UIModuleLinkup;
import com.jkt.rms.commons.utils.ExceptionFactory;
import com.jkt.rms.commons.utils.RMSException;
import com.jkt.rms.commons.utils.SecurityHelper;
import com.jkt.rms.constants.IConstants;
import com.jkt.rms.controller.ChangePasswordController;

import com.jkt.rms.dataservice.AbstractDataService;
import com.jkt.rms.dataservice.UIModuleLinkupDataService;

public class UIModuleLinkupDataServiceImpl extends AbstractDataService<UIModuleLinkup> implements
		UIModuleLinkupDataService{

	private static final Logger LOG = Logger.getLogger(UIModuleLinkupDataServiceImpl.class);
	@Override
	protected Class<UIModuleLinkup> getReferenceClass() {
		return UIModuleLinkup.class;
	}
	
	@SuppressWarnings("unchecked")
	public List <String>  findRolesByScreenName(String screenName) 
	{
		List<String> uniqueroles = null;
		try
		{
			String hql ="select distinct mrl.role_name from ui_module_linkup uml , module_role_linkup mrl " +
					    "where uml.screen_name = :screenName and   uml.module_id   = mrl.module_id";

			Query query = getSession().createSQLQuery(hql);
			query.setParameter("screenName", screenName,Hibernate.STRING);
			uniqueroles = query.list();
			
			getSession().close();
			return uniqueroles;			
		}
		catch(Exception e)
		{
			ExceptionFactory.createRMSException(LOG, e.getCause());
			return uniqueroles;
		}
	     
	}
}